package cn.edu.nju.software.model.administrator;

import cn.edu.nju.software.model.user.Booking;

public class BookingAtScene extends Booking {

	public boolean canBook(String hall, String movie, int count, String username) {
		int surplus = dbHelper.fetchSurplus(hall, movie);
		System.out.println("surplus for " + hall + "-" + movie + ": " + surplus);
		if (count > surplus) {
			flag = NT;
			return false;
		}
		
		int balance = dbHelper.fetchBalance(username);
		System.out.println("balance for " + username + ": " + balance + "\n");
		int price = fetchPrice(hall, movie);
		int cost = price * count;
		if (balance < cost) {
			flag = NM;
			return false;
		}
		return true;
	}
	
	public void book(String username, int count, String hall, String movie) {
		int price = fetchPrice(hall, movie);
		int cost = price * count;
		int balance = dbHelper.fetchBalance(username) - cost;
		System.out.println(" balance for " + username + ": " + balance);
		dbHelper.updateBalance(username, balance);

		book(count, hall, movie);
	}
	
	public void book(int count, String hall, String movie) {
		int surplus = dbHelper.fetchSurplus(hall, movie) - count;
		System.out.println(" surplus for " + hall + "-" + movie + ": " + surplus);
		dbHelper.updateSurplus(hall, movie, surplus);
	}
}
